/*****************************************
 *  所有版权(c) 上海塔齐通讯技术有限公司       *
 *****************************************/
package com.touch.sysif.sms.api.client;

import java.net.URL;
import java.rmi.RemoteException;

import org.apache.axis.client.Service;

import com.touch.sysif.sms.api.SmsMessageServiceSoapBindingStub;
import com.touch.sysif.sms.api.model.SmsMessage;
import com.touch.sysif.sms.api.model.SmsReport;

/**
 * 
 * @version $Revision: 1.0 $ 
 * @author yanxiao
 * @date: Jan 21, 2014
 * @time: 3:57:10 AM
 */
public class WsSmsClient extends AbstractSmsClient {
	SmsMessageServiceSoapBindingStub stub;
	
	@Override
	public void init(String configFile) {
		super.init(configFile);
		try {
			URL url = new URL(config.getProperty("ws.url"));
			stub = new SmsMessageServiceSoapBindingStub(url ,new Service());
			stub.setPortName("SmsMessageService");
		} catch (Exception e) {
			throw new RuntimeException("初始化失败，请检查配置文件！");
		}
	}
	/**
	 * @see com.touch.sysif.sms.api.SmsClient#activeTest()
	 */
	public void activeTest() {

	}

	/**
	 * @see com.touch.sysif.sms.api.SmsClient#batchSend(SmsMessage[])
	 */
	public String[] batchSend(SmsMessage[] message) {
		try {
			return stub.batchSend(username, password, message);
		} catch (RemoteException e) {
			return null;
		}
	}

	/**
	 * @see com.touch.sysif.sms.api.SmsClient#getSmsMessage()
	 */
	public SmsMessage[] getSmsMessage() {
		try {
			return stub.getSmsMessage(username, password);
		} catch (RemoteException e) {
			return null;
		}
	}

	/**
	 * @see com.touch.sysif.sms.api.SmsClient#getSmsReports(String, String)
	 */
	public SmsReport[] getSmsReports(String batchId, String destAddr) {
		try {
			return stub.getSmsReports(username, password, batchId, destAddr);
		} catch (RemoteException e) {
			return null;
		}
	}

	/**
	 * @see com.touch.sysif.sms.api.SmsClient#send(SmsMessage)
	 */
	public String send(SmsMessage message) {
		try {
			return stub.send(username, password, message);
		} catch (RemoteException e) {
			return null;
		}
	}

}
